package com.lzy.huijinjiazu.mvp.model;

import android.app.Application;
import android.content.res.TypedArray;
import android.support.v4.app.Fragment;

import com.flyco.tablayout.listener.CustomTabEntity;
import com.google.gson.Gson;
import com.jess.arms.integration.IRepositoryManager;
import com.jess.arms.mvp.BaseModel;

import com.jess.arms.di.scope.ActivityScope;

import javax.inject.Inject;

import com.lzy.huijinjiazu.R;
import com.lzy.huijinjiazu.mvp.contract.MainContract;
import com.lzy.huijinjiazu.mvp.model.entity.TabEntity;
import com.lzy.huijinjiazu.mvp.ui.fragment.FinanceFragment;
import com.lzy.huijinjiazu.mvp.ui.fragment.HomeFragment;
import com.lzy.huijinjiazu.mvp.ui.fragment.JoinFragment;
import com.lzy.huijinjiazu.mvp.ui.fragment.MyAssetsFragment;
import com.lzy.huijinjiazu.mvp.ui.fragment.MyFragment;
import com.lzy.huijinjiazu.mvp.ui.fragment.ShoppingMallFragment;

import java.util.ArrayList;


@ActivityScope
public class MainModel extends BaseModel implements MainContract.Model {
    private Gson mGson;
    private Application mApplication;

    @Inject
    public MainModel(IRepositoryManager repositoryManager, Gson gson, Application application) {
        super(repositoryManager);
        this.mGson = gson;
        this.mApplication = application;
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        this.mGson = null;
        this.mApplication = null;
    }

    @Override
    public ArrayList<CustomTabEntity> getTabLayout() {
        String[] tabTitle = mApplication.getResources().getStringArray(R.array.home_tab);
        TypedArray selectedIcon = mApplication.getResources().obtainTypedArray(R.array.homt_tab_selected_icon);
        TypedArray unselectedIcon = mApplication.getResources().obtainTypedArray(R.array.homt_tab_unselected_icon);
        ArrayList<CustomTabEntity> tabEntity = new ArrayList<>();
        for (int i = 0; i < tabTitle.length; i++) {
            tabEntity.add(new TabEntity(tabTitle[i], selectedIcon.getResourceId(i, 0), unselectedIcon.getResourceId(i, 0)));
        }
        return tabEntity;
    }

    @Override
    public Fragment[] getTabFragment() {
        return new Fragment[]{
                HomeFragment.newInstance(),
                FinanceFragment.newInstance(),
                ShoppingMallFragment.newInstance(),
                JoinFragment.newInstance(),
                MyFragment.newInstance()
        };
    }
}